Skip to content

fix(web): use session flavor label in voice context formatters#1

Draft
heavygee wants to merge 1 commit into
mainfrom
fix/voice-flavor-labels
Draft

fix(web): use session flavor label in voice context formatters#1
heavygee wants to merge 1 commit into
mainfrom
fix/voice-flavor-labels

Conversation

@heavygee
Copy link
Copy Markdown
Owner

@heavygee heavygee commented May 24, 2026

Summary

Replaces hardcoded Claude Code strings in voice context injections with the active session's flavor label (Cursor, Codex, Gemini, OpenCode, etc.) sourced from getFlavorLabel() in @hapi/protocol. Falls back to coding agent for unknown or missing flavors.

web/src/realtime/hooks/contextFormatters.ts — threads agentLabel (optional, default 'coding agent') through formatPlainText, formatPermissionRequest, formatMessage (text blocks + tool-call lines), formatNewMessages, formatHistory, formatSessionFull, formatReadyEvent.

web/src/realtime/hooks/voiceHooks.ts — adds getAgentLabel(session) helper using getFlavorLabel() from @hapi/protocol; passes label into all formatter calls.

Why shared/src/voice.ts is not touched

The system prompt in voice.ts contains example text that references "Claude" (e.g. the permission request example: "Claude wants to run a bash command"). We considered updating this but deliberately chose not to.

The argument for changing it: be as accurate as possible even in the ConvAI prompt.

The argument against, which won: once this PR (and tiann#682) are merged, every context update ConvAI receives will carry the correct agent label — "Cursor is requesting permission to use Bash", not "Claude Code is requesting...". At that point ConvAI's spoken responses will naturally reflect the right terminology, because LLMs follow the context they receive rather than parroting example text from a system prompt verbatim. The voice.ts wording only remains a real-world problem if these formatter fixes are not in place — which is an argument for merging this PR, not for also editing the system prompt. Touching system prompt wording without that being strictly necessary felt like stepping into editorial territory that belongs to the maintainers.

Happy to follow up separately on voice.ts if desired once these changes land.

Test plan

  • bun test web/src/realtime/hooks/contextFormatters.test.ts (8 tests — all assert label appears, none hardcode Claude Code)
  • Manual: voice session active, speech input and response verified end-to-end
  • Manual: ConvAI response correctly reflected active session context

Issues

Fixes tiann#680

@heavygee heavygee force-pushed the fix/voice-flavor-labels branch 3 times, most recently from e68ef31 to 8179263 Compare May 24, 2026 23:41
Replaces hardcoded 'Claude Code' strings in voice context injections with
the active session's flavor label (Cursor, Codex, Gemini, etc.) via
getFlavorLabel() from @hapi/protocol. Falls back to 'coding agent' for
unknown or missing flavors.

Threads an agentLabel param through formatMessage, formatPermissionRequest,
formatReadyEvent, formatNewMessages, formatHistory, and formatSessionFull.
voiceHooks resolves the label once per call via session.metadata.flavor.

Fixes tiann#680

via [HAPI](https://hapi.run)

Co-Authored-By: HAPI <noreply@hapi.run>
@heavygee heavygee force-pushed the fix/voice-flavor-labels branch from 8179263 to 9402685 Compare May 25, 2026 09:49
heavygee added a commit that referenced this pull request Jun 5, 2026
The native-fallback probe previously returned true whenever FCM was
configured AND devices were registered, which suppressed web-push for
the namespace. The HAPI Bot correctly pointed out the gap: if the FCM
pipeline silently breaks (expired service-account key, sustained 5xx,
OAuth token-fetch failure, network blackhole) the operator gets nothing
on either channel until they manually intervene.

Approach (deliberate, not the bot's exact suggested fix):

- FcmService now keeps a small rolling window (last 8 outcomes) of send
  attempts and exposes `isHealthy()`. The threshold is 5+/8 failures =
  unhealthy; the buffer starts empty so a freshly-booted hub is
  optimistic ("innocent until proven guilty") and does not double-fire
  on event #1.
- Token-fetch failure (`getFcmAccessToken` throws) now records exactly
  one health-failure (not one per device), short-circuits the send
  loop, and returns a result so `sendToNamespace` no longer leaks the
  exception.
- `invalid` token responses are explicitly excluded from the health
  buffer because they are per-device facts (rotated/uninstalled token),
  not pipeline failures - FCM was reachable, it just rejected one
  stale token.
- `buildNativeFallbackProbe` now optionally accepts the FcmService and
  short-circuits to "let web-push fire" when health is bad, before it
  even queries the device registry. The single-arg call shape is still
  supported for back-compat.

Why not the bot's exact suggestion ("invert: call FCM first, fall back
on result.sent === 0"):
- Couples PushNotificationChannel to FcmService and FcmSendPayload,
  reversing the clean parallel-channel architecture established earlier
  in this PR.
- Treats every transient single-event failure as fallback-worthy, which
  re-opens the duplicate-notification race that the suppression logic
  was added to close (FCM HTTP timeout that delivers later + the web
  push we sent in the meantime = two pings).
- A rolling health window only flips on sustained breakage, which is
  the actual operational scenario the bot is worried about.

The wrist-first design intent ("FCM fires unconditionally, web-push is
suppressed for the same namespace") documented in
docs/api/native-companion-contract.md is preserved on the happy path.
The probe only re-enables web-push when there is concrete evidence the
native pipeline is not delivering.

Tests:
- New FcmService.isHealthy suite covers empty-buffer, threshold flip,
  recovery as failures age out of the window, invalid-token exclusion,
  and network-error path.
- nativeFallbackProbe gains coverage for the unhealthy-but-registered,
  healthy-and-registered, and absent-fcmService (back-compat) cases.
- All 292 hub tests still pass; typecheck clean.

Co-authored-by: Cursor <cursoragent@cursor.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(voice): context formatters hardcode "Claude Code" for all agent flavors

1 participant